package org.theSeed.base.pojo.dto;

import org.theSeed.base.pojo.config.NameThreadFactory;

import java.util.concurrent.*;

public class ThreadPoolDto {
    /**
     * 核心线程数
     */
    private int corePoolSize;

    /**
     * 最大线程数
     */
    private int maximumPoolSize;

    /**
     * 存活时间/秒
     */
    private long keepAliveTime;

    /**
     * 任务队列
     */
    private BlockingQueue<Runnable> workQueue;

    /**
     * 线程工厂
     */
    private ThreadFactory threadFactory = NameThreadFactory.getDefaultThreadFactory();

    /**
     * 拒绝策略
     */
    private RejectedExecutionHandler handler = new ThreadPoolExecutor.CallerRunsPolicy();

    public Executor createExecutor(){
        return new ThreadPoolExecutor(corePoolSize,maximumPoolSize,keepAliveTime,TimeUnit.SECONDS,workQueue,threadFactory,handler);
    }
}
